﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using PMSGSC.DAL;
using PMSGSC.BLL;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
namespace PMSGSC.App
{
    public partial class frmShowIOList : DevExpress.XtraEditors.XtraForm
    {
        public frmShowIOList(List<Invoice> invoiceList, frmMain main)
        {
            InitializeComponent();
            invoiceBindingSource.DataSource = invoiceList;
            objMain = main;
        }
        private Invoice invoice;
        private frmMain objMain;
        private void gridView1_ShowingEditor(object sender, CancelEventArgs e)
        {
            e.Cancel = true;
        }
        private void DoRowDoubleClick(GridView view, Point pt)
        {
            GridHitInfo info = view.CalcHitInfo(pt);

            if (info.InRow || info.InRowCell)
            {
                if (info.RowHandle != GridControl.NewItemRowHandle)
                {
                    invoice = invoiceBindingSource.Current as Invoice;
                    List<Invoice> invoices = new List<Invoice>();
                    invoices.Add(invoice);
                    if (invoice.Type.Value)
                    {
                        frmStockIn stockIn = new frmStockIn(invoices, objMain);
                        stockIn.MdiParent = objMain;
                        stockIn.Show();
                    }
                    else
                    {
                        frmStockOut stockOut = new frmStockOut(invoices, objMain);
                        stockOut.MdiParent = objMain;
                        stockOut.Show();
                    }
                }
            }
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            GridView view = (GridView)sender;

            Point pt = view.GridControl.PointToClient(Control.MousePosition);

            DoRowDoubleClick(view, pt);
        }

        private void gridView1_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                e.Info.DisplayText = (e.RowHandle + 1).ToString();
            }
        }
    }
}